import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
		'upUserInfo'
    ]),
	//切换分类
	selectTab(index,color,id,name){
		this.current = index
		this.currentColor = color
		this.current_typeName = name
		this.getAllTag(id)
	},
	toSearch(){
		uni.navigateTo({
			url: '/pages/index/search'
		})
		// this.$toast.msg("暂未开放！", {
		// 	icon: 1
		// })
	},
	toNotice(){
		uni.navigateTo({
			url: '/pages/my/notice'
		})
	},
	toLogin(){
		uni.navigateTo({
			url: '/pages/publics/login'
		})
	},
	//标签点击记录
	tagClick(id,index,points){
		let that = this
		that.currentNumber = points
		that.$httpRequest.request({
			that: that,
			url: 'h5/tagClick',
			params: {
				tagId:id,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.topicList[index].clicked = true
					that.showNumber = true
					setTimeout(()=>{
						that.showNumber = false
					},500)
				}else{
					that.$toast.msg(res.message, {
					    icon: 1
					})
				}
			
			}
		})
	},
	//保密弹窗
	openTagSecret(id,name){
		this.clicked_tagId = id
		this.clicked_tagName = name
		this.$refs.confirmPopup.open()
		
	},
	close(){
		this.$refs.confirmPopup.close()
	},
	//标签设置保密
	tagSecret(){
		let that = this
		that.$httpRequest.request({
			that: that,
			url: 'h5/tagSecret',
			params: {
				tagId:that.clicked_tagId,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					
				}else{
					that.$toast.msg(res.message, {
					    icon: 1
					})
				}
			
			}
		})
	},
	//标签取消保密
	tagCancelSecret(){
		let that = this
		this.close()
		that.$httpRequest.request({
			that: that,
			url: 'h5/tagCancelSecret',
			params: {
				tagId:that.clicked_tagId,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.$toast.msg('撤销成功', {
					    icon: 1
					})
				}else{
					that.$toast.msg(res.message, {
					    icon: 1
					})
				}
			
			}
		})
	},
	//获取所有分类
	getAllCategory(){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getAllCategory',
			params: {
				// id:that.id,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.classify = res.data
					that.getAllTag(that.classify[0].id)
					that.current_typeName = that.classify[0].name
					that.currentColor = that.classify[0].colorLight
				}
			
			}
		})
	},
	//获取指定分类的标签
	getAllTag(id){
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/getAllTag',
			params: {
				categoryId:id,
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.topicList = res.data
					
				}
			
			}
		})
	},
	getUserInfo() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/info',
			params: {
	
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
				} else {
					that.upUserInfo({})
				}
			}
		})
	},
}